package com.example.test.dialogfactory;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import easier.app.x.crash.CrashWatcher;
import easier.log.logger.Logger;

public class CrashActivity extends AppCompatActivity {

    private Button mCreateCrash;
    private Button mThreadCrash;

    public static void start( Context context ) {

        Intent starter = new Intent( context, CrashActivity.class );
        context.startActivity( starter );

        new CrashWatcher() {
            @Override
            protected void uncaughtException( @NonNull Thread t, @NonNull Throwable e ) {

                super.uncaughtException( t, e );
                Logger.e( e, "线程名字" + t.getName() );
            }
        }.start();
    }

    @Override
    protected void onCreate( Bundle savedInstanceState ) {

        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_crash );
        initView();
    }

    private void initView() {

        mCreateCrash = (Button) findViewById( R.id.createCrash );
        mCreateCrash.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View v ) {

                LinearLayout v1 = (LinearLayout) v;
            }
        } );

        mThreadCrash = (Button) findViewById( R.id.threadCrash );
        mThreadCrash.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View v ) {

                new Thread( new Runnable() {
                    @Override
                    public void run() {

                        LinearLayout v1 = (LinearLayout) v;
                    }
                } ).start();
            }
        } );
    }
}